<?php
/**
* @version		$Id: dynl_control.php 1 2007-01-11 22:03:46Z friesengeist $
* @package		Dynlist
* @copyright	Copyright (C) 2005 - 2007 Dynlist. All rights reserved.
* @license		GNU/GPL, see LICENSE.php
* Dynlist is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/
/**
* Dynlist application control class
*
* Manage all application and user actions and call proper objects.
* All aplication runs based on this method, that receives the string command
* that came from link or parent application that passes this commants to 
* method process_action().
*
* @package		Dynlist
* @final
*/
class Dynl_control
{
	/**
	 * Singleton instance.
	 *
	 * @var object Dynl_control object
	 * @access private
	 */
	var $_instance;

	/**
	* Class constructor.
	* Exists only to defeat instantiation.
	*
	* @access protected
	*/
	function dynl_control()
	{
		
	}

	/**
	* Returns the instance created or if not created, create new.
	* It's ensure that this class be a singleton pattern.
	*
	* @access protected
	* @param char xcode
	*/
	function get_instance()
	{
		if (!isset($this->_instance)) {
			$this->_instance = new dynl_control();
		}
		return $this->_instance;
	}
	
	/**
	* Process all actions from user and call proper objects.
	*
	* @access protected
	* @param char xcode_in
	*/
	function process_action($xcode_in)
	{
	// Parse xcodes:
	// 0 -> class
	// 1 -> object
	// 2 -> method
	// 3 -> parameter 1
	// 4 -> parameter 2	
	$xcode_out = spliti ("!", $xcode_in);
	//print_r($xcode_out);
    
	switch	($xcode_out[0]) {
		// Functions for Dynlist Catalog.
		case 'catalog':
		  	//$catalog = dynl_catalog::get_instance();
		  	$catalog = new dynl_catalog();
		  	switch ($xcode_out[2]) {
		  		// Show list of Dynlists.
			  	case 'show_catalog':
			  		$catalog->show_catalog();
			  		break;
			  	// Show Dynlist data.
			  	//case 'show_data':
			  		//$catalog->show_data();
			  		//break;
		  		// Creates new Dynlist structure.
			  	case 'new':
		  			$catalog->new_structure();
		  			break;
		  		// Edits existing Dynlist structure.
		  		case 'edit':
		  			$catalog->edit_structure($xcode_out[]);
		  			break;
		  		// Deletes existing Dynlist strucuture.
		  		case 'delete':
			  		$catalog->delete_structure($xcode_out[1]);
			  		break;
			}
			break;
		
		// Functions for Dynlist Data.	  
		case 'data':
		  	$data = new dynl_data($xcode_out[1]);
		  	switch ($xcode_out[2]) {
		  		// Show Dynlist data.
			  	case 'show_data':
			  		$data->show_data();
			  		break;
		  		// Creates new Dynlist structure.
			  	case 'new_record':
		  			$data->new_record();
		  			break;
		  		// Edits existing Dynlist structure.
		  		case 'edit_record':
		  			$data->edit_record($xcode_out[3]);
		  			break;
		  		// Save record.
		  		case 'save_record':
			  		$data->save_record($xcode_out[3]);
			  		break;
				// Deletes existing Dynlist strucuture.
		  		case 'delete_record':
			  		$data->delete_record($xcode_out[3]);
			  		break;
				// Cancel last changes.
		  		case 'cancel':
			  		$data->cancel();
			  		break;
			}
			break;
		
		// Functions for Dynlist structure maintenance.  		  
		case 'structure':
			break;
		
		// Functions for Dynlist data maintenance.  
		case 'record':
			break;
		}
		
		//print_r($xcode_out);
	}

}
?>
